# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Tobias Powalowski <tpowa@archlinux.org>

pkgname=cfitsio
pkgver=4.3.1
pkgrel=1
epoch=1
pkgdesc='A library of C and Fortran subroutines for reading and writing data files in FITS (Flexible Image Transport System) data format'
arch=(loong64 x86_64)
url='https://heasarc.gsfc.nasa.gov/fitsio/'
license=(custom)
depends=(curl
         glibc
         zlib)
source=(https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/$pkgname-$pkgver.tar.gz)
sha256sums=('47a7c8ee05687be1e1d8eeeb94fb88f060fbf3cd8a4df52ccb88d5eb0f5062be')

prepare() {
  cd $pkgname-$pkgver
  sed -e 's|LDFLAGS=.*|LDFLAGS="$LDFLAGS"|g' -i configure.in # Fix LDFLAGS
  autoreconf -vi
}

build() {
  cd $pkgname-$pkgver
  ./configure --prefix=/usr --enable-reentrant
  make shared
  make utils
}

check() {
  cd $pkgname-$pkgver
  LD_LIBRARY_PATH=. ./testprog > testprog.lis
  [[ -z $(diff testprog.lis testprog.out) ]] || return 1
  [[ -z $(cmp testprog.fit testprog.std) ]] || return 1
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install

  install -D -m644 License.txt \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

# Fix conflicts with ccfits and smem
  rm "$pkgdir"/usr/bin/{cookbook,smem,testprog}
}
